﻿package mortal.game.view.copy.escort
{
    import Message.Public.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.escort.vo.*;
    import mortal.game.view.mainUI.roleAvatar.*;
    import mortal.game.view.skill.*;
    import mortal.game.view.skill.panel.render.*;
    import mortal.mvc.core.*;

    public class EscortCopyHarryBar extends EscortCopyShortcutBarBase
    {
        private var _skill0:SkillItem;
        private var _skill1:SkillItem;
        private static var _instance:EscortCopyHarryBar;

        public function EscortCopyHarryBar(param1:String)
        {
            _titleName = param1;
            return;
        }// end function

        private function onUseSkillHandler(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget as SkillItem;
            if (_loc_2.isCDing)
            {
                MsgManager.showRollTipsMsg(Language.getString(35184));
                return;
            }
            var _loc_3:* = new EscortCopyOperVo(EEscortOper._EEscortOperUseSkill);
            _loc_3.extend = SkillInfo(_loc_2.dragSource).skillId;
            if (ThingUtil.selectEntity)
            {
                if (EntityRelationUtil.isFriend(ThingUtil.selectEntity.entityInfo.entityInfo))
                {
                    _loc_3.entityId = ThingUtil.selectEntity.entityInfo.entityInfo.entityId;
                }
                else
                {
                    _loc_3.entityId = Cache.instance.copy.escort.nullSEntityId;
                }
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.EscortCopyOper, _loc_3));
            return;
        }// end function

        private function onBufferUpdate(param1:Object = null) : void
        {
            var _loc_3:Boolean = false;
            var _loc_4:BuffData = null;
            var _loc_2:* = Cache.instance.buff.buffInfoArray;
            for each (_loc_4 in _loc_2)
            {
                
                if (_loc_4.tbuff.buffId == 53010000 && _loc_4.tbuff.type == EBuffType._EBuffTypeAmbush)
                {
                    _loc_3 = true;
                    break;
                }
            }
            this._skill0.visible = !_loc_3;
            this._skill1.visible = _loc_3;
            return;
        }// end function

        override public function update(param1:Object, ... args) : void
        {
            var _loc_4:SkillInfo = null;
            var _loc_5:int = 0;
            var _loc_6:SEscortSkill = null;
            args = param1 as Array;
            for each (_loc_6 in args)
            {
                
                _loc_4 = new SkillInfo();
                _loc_4.tSkill = SkillConfig.instance.getInfoById(_loc_6.skillId);
                SkillItem(this["_skill" + _loc_5]).setSkillInfo(_loc_4);
                _loc_5++;
            }
            this.onBufferUpdate();
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            if (!this._skill1)
            {
                this._skill0 = new SkillItem();
                this._skill0.setBg();
                this._skill0.isShowFreezingEffect = true;
                this._skill1 = new SkillItem();
                this._skill1.setBg();
                this._skill1.isShowFreezingEffect = true;
                this._skill0.addEventListener(MouseEvent.CLICK, this.onUseSkillHandler);
                this._skill1.addEventListener(MouseEvent.CLICK, this.onUseSkillHandler);
            }
            this._skill0.visible = false;
            this._skill1.visible = false;
            UIFactory.setObjAttri(this._skill0, 106, 18, -1, -1, this);
            UIFactory.setObjAttri(this._skill1, 106, 18, -1, -1, this);
            NetDispatcher.addCmdListener(ServerCommand.BufferUpdate, this.onBufferUpdate);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            NetDispatcher.removeCmdListener(ServerCommand.BufferUpdate, this.onBufferUpdate);
            return;
        }// end function

        public static function get instance() : EscortCopyHarryBar
        {
            return _instance;
        }// end function

        public static function get hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
